package com.oss.controller;

import com.oss.bean.UpLoadResult;
import com.oss.service.FileUpLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/oss")
public class OssController {
    @Autowired
    private FileUpLoadService fileUpLoadService;

    @PostMapping("/upload")
    @ResponseBody
    public UpLoadResult upload(@RequestParam("file") MultipartFile  multipartFile){

        return  fileUpLoadService.upload(multipartFile);
    }

    @RequestMapping("/download")
    @ResponseBody
    public void download(String fileName, HttpServletRequest request, HttpServletResponse response) throws IOException {

        fileUpLoadService.download(request,response,fileName);
    }

    @PostMapping("/delete")
    @ResponseBody
    public UpLoadResult delete(String fileName){

        return  fileUpLoadService.delete(fileName);
    }



}
